package com.hyper_yang._05_juc.chap02;

import java.util.concurrent.locks.ReentrantLock;

/*
public ReentrantLock(boolean fair) {
        sync = fair ? new FairSync() : new NonfairSync();
    }
 */
public class ReentrantLockDemo2 {

    private final ReentrantLock lock = new ReentrantLock(true); // 默认非公平锁     true表示公平锁

    public void a() {
        lock.lock();
        lock.lock();
        lock.lock();
        this.b();
        System.out.println("a");
        lock.unlock();
        lock.unlock();
        lock.unlock();
    }

    public void b() {
        lock.lock();
        System.out.println("b");
        lock.unlock();
    }

    public static void main(String[] args) {
        new ReentrantLockDemo().a();
    }
}